# -*- coding: utf-8 -*-
"""
读txt
"""

import os

def open_file(filename, mode='r'):
    return open(filename, mode, encoding='utf-8', errors='ignore')


# 可以读取大文件
def read_file(filename):
    with open_file(filename) as f:
        while True:
            line = f.readline().strip()
            if not line:
                break
            yield line, len(line)


def get_filepaths(path, keep='.docx'):
    '''获取path目录下所有指定类型文件路径'''
    files = []
    for maindir, _, file_name_list in os.walk(path):
        for file in file_name_list:
            apath = os.path.join(maindir, file)
            if apath.endswith(keep):
                files.append(apath)
    return files
